package com.ay.shardingshere.controller;

import com.ay.shardingshere.entity.Dict;
import com.ay.shardingshere.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: ay
 * @Date: 2021/6/24
 * @Description: 字典测试类
 **/
@RestController
@RequestMapping("dict")
public class DictController {

    @Autowired
    private DictService dictService;


    /**
     * 保存字典
     */
    @PostMapping
    public void save(){
        for (int i = 0; i < 20; i++) {
            Dict dict = new Dict();
            dict.setDictKey("key" + i);
            dict.setDictValue("value" + i);
            dictService.save(dict);
        }
    }

    /**
     * 查询字典列表
     * @return
     */
    @GetMapping
    public List<Dict> list(){
        return dictService.list();
    }
}
